path='C:\Users\Tom�s\Documents\1. Regehr Lab\Data summary'
load([path  '\MossyFiberStimV2.mat'])

%% CCs first
numb=nansum(CCsLag,2);
nCC=sum(numb>0);

figure;
for i=1:nCC
    d{1}=CCsLag(i,:)
    subaxis(nCC,1,i,'spacingvert',0.01)
    h=histogram(d{1},[0:0.2:10],'facecolor',rgb('deepskyblue'))
% xlim([0 10])
y=ylim;
hold on
plot(d{1}, -y(2)/3+(rand(numel(d{1}),1)*(y(2)/6)),'o','color',[0.4 0.4 0.4 0.5])
box off
axis off
[val loc]=max(h.Values);
histpeak=(loc*h.BinWidth)+h.BinLimits(1)-h.BinWidth/2;
vline(histpeak,'--r');
xlim([0 10])
end

%% Now MLI
numb=nansum(MLIMs,2);
nMLI=sum(numb>0);

figure;
for i=1:nMLI
    d{1}=MLIMs(i,:)
    subaxis(nMLI,1,i,'spacingvert',0.01)
    h=histogram(d{1},[0:0.2:10],'facecolor',rgb('lightcoral'))
% xlim([0 10])
y=ylim;
hold on
plot(d{1}, -y(2)/3+(rand(numel(d{1}),1)*(y(2)/6)),'o','color',[0.4 0.4 0.4 0.5])
box off
axis off
[val loc]=max(h.Values);
histpeak=(loc*h.BinWidth)+h.BinLimits(1)-h.BinWidth/2;
vline(histpeak,'--r');
xlim([0 10])
end




%% plot a cdf of the data
figure;
hold on
for i=1:nMLI
%     cdfplot(CCsLag(i,:))
    test=MLIMs(i,:)
    [f,x] = ecdf(test)
    if max(x)<10
        f(end+1)=f(end);
        x(end+1)=10;
    end
% plot(x,f)
a=test(~isnan(test));
result = find(test==a(end));
result=max(result)
   plot(x,f,'color','k','linewidth',1.5)
end

for i=1:nCC
%     cdfplot(CCsLag(i,:))
    test=CCsLag(i,:)
    [f,x] = ecdf(test)
    if max(x)<10
        f(end+1)=f(end);
        x(end+1)=10;
    end
% plot(x,f)
a=test(~isnan(test));
result = find(test==a(end));
result=max(result)
  % plot(x,f*numel(f)/result,'color',rgb('deepskyblue'),'linewidth',1.5)
   plot(x,f,'color',rgb('deepskyblue'),'linewidth',1.5)
end

ylabel({'cumulative distribution'})
set(gcf,'color','white');
set(gca,'FontSize', 18);
xlim([0 10])

[f,x] = ecdf(test)

